﻿using System.Collections.Generic;
using System.Configuration;
using System.IO;
using Home.Web.Models.Category;
using Home.Web.Models.ImageInfo;

namespace Home.Web.Services.Carousel
{
    public static class CarouselService
    {
        public static List<Category> GetCategories()
        {
            var categories = new List<Category>();
            var imagePath = ConfigurationManager.AppSettings["imagesPath"];

            var dInfo = new DirectoryInfo(imagePath);
            var subdirs = dInfo.GetDirectories();
            foreach (var d in subdirs)
            {
                var cat = new Category{Name=d.Name};
                categories.Add(cat);
            }
            return categories;
        }
        public static List<ImageInfo> GetImageInfos(string category)
        {
            var imageInfos = new List<ImageInfo>();
            var imagePath = Path.Combine(ConfigurationManager.AppSettings["imagesPath"], category);
            var contentPath = "/Content/images/" + category + "/";
            
            if (Directory.Exists(imagePath))
            {
                string[] files = Directory.GetFiles(imagePath);
                foreach (var f in files)
                {
                    var ii = new ImageInfo {Url = contentPath + Path.GetFileName(f)};
                    imageInfos.Add(ii);
                }
            }

            return imageInfos;
        } 
    }
}